package com.mfangsoft.zhuangjialong.integration.usermanage.controller;

import java.text.ParseException;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mfangsoft.zhuangjialong.app.applogin.model.CustomerEntity;
import com.mfangsoft.zhuangjialong.app.applogin.service.CustomerService;
import com.mfangsoft.zhuangjialong.app.order.model.OrderPromote;
import com.mfangsoft.zhuangjialong.app.order.service.IAppOrderService;
import com.mfangsoft.zhuangjialong.article.model.ArticleDetailModel;
import com.mfangsoft.zhuangjialong.common.context.UserContext;
import com.mfangsoft.zhuangjialong.common.model.Page;
import com.mfangsoft.zhuangjialong.common.model.ResponseMessage;
import com.mfangsoft.zhuangjialong.common.utils.SysConstant;
import com.mfangsoft.zhuangjialong.integration.activity.model.BaseActivityInfo;
import com.mfangsoft.zhuangjialong.integration.gift.model.BaseGift;
import com.mfangsoft.zhuangjialong.integration.order.model.BaseOrder;
import com.mfangsoft.zhuangjialong.integration.usermanage.model.BaseUserManage;
import com.mfangsoft.zhuangjialong.integration.usermanage.model.BaseUserManagerModel;
import com.mfangsoft.zhuangjialong.integration.usermanage.model.CustomerUserManagerCommunicate;
//import com.mfangsoft.zhuangjialong.integration.usermanage.model.CustomerCommunicateEntity;
import com.mfangsoft.zhuangjialong.integration.usermanage.model.SellerPointEntity;
import com.mfangsoft.zhuangjialong.integration.usermanage.model.UserCustomerReportEntity;
import com.mfangsoft.zhuangjialong.integration.usermanage.model.UserManagerDept;
import com.mfangsoft.zhuangjialong.integration.usermanage.model.UserManagerTask;
import com.mfangsoft.zhuangjialong.integration.usermanage.model.UserManagerTaskModel;
import com.mfangsoft.zhuangjialong.integration.usermanage.service.UserManageService;

@Controller
@RequestMapping("/server")
public class UserManageController {

	@Autowired
	private UserManageService userManageServiceImpl; 
	@Autowired
	private CustomerService customerImpl;
	@Autowired
	private IAppOrderService appOrderServiceImpl;

	
	/**   
	 * 新增人员
	 * @param 
	 * @return
	 */
	
	@RequestMapping(value="/addUserManage",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<String> addUserManage(@RequestBody BaseUserManage baseUserManage){
		ResponseMessage<String> message = new ResponseMessage<String>();
		try {
		    
			userManageServiceImpl.addUserManage(baseUserManage);
	
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;	
	}
	
	/**
	 * 根据省市区获取当前登陆用户下的一级店铺下拉选
	 */
	@RequestMapping(value="/selectStairShopsByUid",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<Map<String,Object>> selectStairShopsByUid(@RequestBody Map<String,Object> map){
		ResponseMessage<Map<String,Object>> message = new ResponseMessage<Map<String,Object>>();
		try {
			Map<String,Object> result = userManageServiceImpl.selectStairShopsByUid(map.get("code").toString());
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			message.setResult(result);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;	
	}
	
	/**
	 * 人员列表
	 * @param baseActivityInfo
	 * @return
	 */
	
	@RequestMapping(value="/selectUserManagePage",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<Page<Map<String,Object>>> selectUserManagePage(@RequestBody Page<Map<String,Object>> page){
		ResponseMessage<Page<Map<String,Object>>> message = new ResponseMessage<Page<Map<String,Object>>>();
		try {
			Page<Map<String,Object>> baseUserManagerModelList =userManageServiceImpl.selectUserManagePage(page);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			message.setResult(baseUserManagerModelList);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
	
		return message;
		
		
	}
	
	/**
	 * 相关数据:客户推广
	 */
	@RequestMapping(value="/related/customer",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<Page<CustomerEntity>> relatedCustomer(@RequestBody Page<CustomerEntity> page){
		ResponseMessage<Page<CustomerEntity>> message = new ResponseMessage<Page<CustomerEntity>>();
		try {
			Page<CustomerEntity> customers = customerImpl.selectCustomersByUserManagerId(page);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			message.setResult(customers);
		} catch (Exception e) {
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;
	}
	
	/**
	 * 相关数据:客户推广/沟通记录
	 */
	@RequestMapping(value="/related/customer/selectCommunicate",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<CustomerUserManagerCommunicate> relatedCustomerCommunicate(@RequestBody Map<String,Object> map){
		ResponseMessage<CustomerUserManagerCommunicate> message = new ResponseMessage<CustomerUserManagerCommunicate>();
		try {
			CustomerUserManagerCommunicate customers = userManageServiceImpl.selectRelatedCustomerCommunicateForPage(map);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			message.setResult(customers);
		} catch (Exception e) {
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;
	}
	
	
	
	
	/**
	 * 相关数据:订单推广
	 */
	@RequestMapping(value="/related/order",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<Page<OrderPromote>> relatedOrder(@RequestBody Page<OrderPromote> page){
		ResponseMessage<Page<OrderPromote>> message = new ResponseMessage<Page<OrderPromote>>();
		try {
			Page<OrderPromote> orders = appOrderServiceImpl.selectOrdersByUserManagerId(page);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			message.setResult(orders);
		} catch (Exception e) {
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;
	}
	
	/**
	 * 相关数据:积分明细
	 */
	@RequestMapping(value="/related/integral",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<Page<SellerPointEntity>> relatedIntegral(@RequestBody Page<SellerPointEntity> page){
		ResponseMessage<Page<SellerPointEntity>> message = new ResponseMessage<Page<SellerPointEntity>>();
		try {
			Page<SellerPointEntity> integrals = userManageServiceImpl.selectIntegralsByUserManagerId(page);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			message.setResult(integrals);
		} catch (Exception e) {
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;
	}
	
	/**
	 * 相关数据:客户报备查看
	 */
	@RequestMapping(value="/related/customerReport",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<Page<UserCustomerReportEntity>> customerReport(@RequestBody Page<UserCustomerReportEntity> page){
		ResponseMessage<Page<UserCustomerReportEntity>> message = new ResponseMessage<Page<UserCustomerReportEntity>>();
		try {
			Page<UserCustomerReportEntity> customerReport = userManageServiceImpl.selectCustomerReportByUserManagerId(page);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			message.setResult(customerReport);
		} catch (Exception e) {
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;
	}
	
	/**
	 * 客户报备新增
	 */
	@RequestMapping(value="/related/addCustomerReport",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<UserCustomerReportEntity> addCustomerReport(@RequestBody UserCustomerReportEntity userCustomerReportEntity){
		ResponseMessage<UserCustomerReportEntity> message = new ResponseMessage<UserCustomerReportEntity>();
		try {
			userManageServiceImpl.addCustomerReport(userCustomerReportEntity);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
		} catch (Exception e) {
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;
	}
	
	
	/**
	 * 人员查询:根据人员id查询人员
	 * @param baseActivityInfo
	 * @return
	 */
	
	@RequestMapping(value="/selectUserManageOne/{id}",method=RequestMethod.GET)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<BaseUserManagerModel> selectUserManageOne(@PathVariable int id){
		ResponseMessage<BaseUserManagerModel> message = new ResponseMessage<BaseUserManagerModel>();
		try {
			BaseUserManagerModel bum =userManageServiceImpl.selectUserManageOne(id);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			message.setResult(bum);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;
	}
	
	/**
	 * 人员查询:根据人员账号查询人员
	 * @param baseActivityInfo
	 * @return
	 */
	
	@RequestMapping(value="/selectUserManageName",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<BaseUserManage> selectUserManageName(@RequestBody Map<String,Object> map){
		ResponseMessage<BaseUserManage> message = new ResponseMessage<BaseUserManage>();
		try {
			String user_name = map.get("user_name").toString();
			BaseUserManage bum =userManageServiceImpl.selectUserManageName(user_name);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(bum == null?"true":"false");
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;
	}
	
	
	/**
	 * 人员编辑
	 * @param 
	 * @return
	 * @throws 
	 */
	
	@RequestMapping(value="/updateUserManageOne",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<BaseUserManage> updateUserManageOne(@RequestBody BaseUserManage baseUserManage) throws ParseException{
		
		ResponseMessage<BaseUserManage> message = new ResponseMessage<BaseUserManage>();
		try {
			userManageServiceImpl.updateUserManageOne(baseUserManage);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;
	}
	
	/**
	 * 人员编辑密码设置
	 * @param 
	 * @return
	 * @throws 
	 */
	@RequestMapping(value="/updateUserManagePwd",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<BaseUserManage> updateUserManagePwd(@RequestBody BaseUserManage baseUserManage) throws ParseException{
		
		ResponseMessage<BaseUserManage> message = new ResponseMessage<BaseUserManage>();
		try {
			userManageServiceImpl.updateUserManagePwd(baseUserManage);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			message.setResult(baseUserManage);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;
	}
	
	/**
	 * 人员类型管理之新增
	 */
	@RequestMapping(value="/addUserManageDept",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<UserManagerDept> addUserManageDept(@RequestBody UserManagerDept userManagerDept) throws ParseException{
		
		ResponseMessage<UserManagerDept> message = new ResponseMessage<UserManagerDept>();
		try {
			userManageServiceImpl.addUserManageDept(userManagerDept);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;
	}
	
	/**
	 * 人员类型管理之修改
	 */
	@RequestMapping(value="/updateUserManageDept",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<UserManagerDept> updateUserManageDept(@RequestBody UserManagerDept userManagerDept) throws ParseException{
		
		ResponseMessage<UserManagerDept> message = new ResponseMessage<UserManagerDept>();
		try {
			userManageServiceImpl.updateUserManageDept(userManagerDept);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;
	}
	
	
	/**
	 * 人员类型列表
	 */
	@RequestMapping(value="/userManageDepts",method=RequestMethod.GET)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<List<UserManagerDept>> userManageDepts() throws ParseException{
		
		ResponseMessage<List<UserManagerDept>> message = new ResponseMessage<List<UserManagerDept>>();
		try {
			List<UserManagerDept> userManagerDeptList = userManageServiceImpl.selectUserManageDepts();
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			message.setResult(userManagerDeptList);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;
	}
	
	/**
	 * 店铺的活动列表
	 */
//	@RequestMapping(value="/getActivitys/{num}",method=RequestMethod.GET)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<List<BaseActivityInfo>> getActivitys(@PathVariable Integer num) throws ParseException{
		
		ResponseMessage<List<BaseActivityInfo>> message = new ResponseMessage<List<BaseActivityInfo>>();
		try {
			List<BaseActivityInfo> baseActivityInfoList = userManageServiceImpl.getActivitys(num);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			message.setResult(baseActivityInfoList);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;
	}
	
	/**
	 * 人员任务的设置
	 */
//	@RequestMapping(value="/addUerManagerTask",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<UserManagerTask> addUerManagerTask(@RequestBody UserManagerTask userManagerTask) throws ParseException{
		
		ResponseMessage<UserManagerTask> message = new ResponseMessage<UserManagerTask>();
		try {
			userManageServiceImpl.addUerManagerTask(userManagerTask);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;
	}
	
	/**
	 * 人员任务的设置
	 */
	@RequestMapping(value="/addUerManagerTaskBatch",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<UserManagerTask> addUerManagerTaskBatch(@RequestBody Map<String,Object> map) throws ParseException{
		
		ResponseMessage<UserManagerTask> message = new ResponseMessage<UserManagerTask>();
		try {
			userManageServiceImpl.addUerManagerTaskBatch(map);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message; 
	}
	
	/**
	 * 人员任务的批量设置提示框
	 */
//	@RequestMapping(value="/selectUerManagerTaskHint",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
    public ResponseMessage<Map<String,Object>> selectUerManagerTaskHint(@RequestBody Map<String,Object> map) throws ParseException{
		
		ResponseMessage<Map<String,Object>> message = new ResponseMessage<Map<String,Object>>();
		try {
			Map<String,Object> taskMap = userManageServiceImpl.selectUerManagerTaskHint(map);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			message.setResult(taskMap);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message; 
	}
	
	/**
	 * 导购管理的任务设置活动列表
	 */
	@RequestMapping(value="/selectUserActivity",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public Page<Map<String,Object>> selectUserActivity(@RequestBody Page<Map<String,Object>> page){
		try {
			Page<Map<String,Object>> userManagerTaskModelList = userManageServiceImpl.selectUserActivity(page);
			return userManagerTaskModelList;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return page;
	}
	
	/**
	 * 人员设置任务的任务列表
	 */
	@RequestMapping(value="/selectUserManagerActivityTaskList",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public Page<Map<String,Object>> selectUserManagerActivityTaskList(@RequestBody Page<Map<String,Object>> page){
		try {
			Page<Map<String,Object>> userManagerTaskModelList = userManageServiceImpl.selectUserManagerActivityTaskList(page);
			return userManagerTaskModelList;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return page;
	}
	
	/**
	 * 人员设置任务的任务列表的查看详情
	 */
	@RequestMapping(value="/selectUserManagerActivityTaskDetails/{activityTaskId}",method=RequestMethod.GET)
	@ResponseBody
	@CrossOrigin
    public ResponseMessage<Map<String,Object>> selectUserManagerActivityTaskDetails(@PathVariable Long activityTaskId) throws ParseException{
		
		ResponseMessage<Map<String,Object>> message = new ResponseMessage<Map<String,Object>>();
		try {
			Map<String,Object> map = userManageServiceImpl.selectUserManagerActivityTaskDetails(activityTaskId);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			message.setResult(map);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;
	}
	
	/**
	 * 人员设置任务的任务列表的编辑
	 */
	@RequestMapping(value="/updateUserManagerActivityTask",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
    public ResponseMessage<UserManagerTask> updateUserManagerActivityTask(@RequestBody Map<String,Object> map) throws ParseException{
		
		ResponseMessage<UserManagerTask> message = new ResponseMessage<UserManagerTask>();
		try {
			userManageServiceImpl.updateUserManagerActivityTask(map);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message; 
	}
	
	/**
	 * 人员设置任务的任务列表的编辑回显
	 */
	@RequestMapping(value="/selectUserManagerActivityTaskEcho/{activityTaskId}",method=RequestMethod.GET)
	@ResponseBody
	@CrossOrigin
    public ResponseMessage<Map<String,Object>> selectUserManagerActivityTaskEcho(@PathVariable Long activityTaskId) throws ParseException{
		
		ResponseMessage<Map<String,Object>> message = new ResponseMessage<Map<String,Object>>();
		try {
			Map<String,Object> map = userManageServiceImpl.selectUserManagerActivityTaskEcho(activityTaskId);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			message.setResult(map);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;
	}
	
	
	/**
	 * 人员任务设置的树状结构
	 */
	@RequestMapping(value="/selectUserManagerTaskTree",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
     public ResponseMessage<List<Map<String,Object>>> selectUserManagerTaskTree(@RequestBody Map<String,Object> map) throws ParseException{
		
		ResponseMessage<List<Map<String,Object>>> message = new ResponseMessage<List<Map<String,Object>>>();
		try {
			List<Map<String,Object>> taskMap = userManageServiceImpl.selectUserManagerTaskTree(map);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			message.setResult(taskMap);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message; 
	}
	
	/**
	 * 人员的任务查看
	 */
	@RequestMapping(value="/selectUerManagerTask",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<Page<UserManagerTaskModel>> selectUerManagerTask(@RequestBody Page<UserManagerTaskModel> page) throws ParseException{
		
		ResponseMessage<Page<UserManagerTaskModel>> message = new ResponseMessage<Page<UserManagerTaskModel>>();
		try {
			Page<UserManagerTaskModel> userManagerTaskModelList = userManageServiceImpl.selectUerManagerTask(page);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			message.setResult(userManagerTaskModelList);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;
	}
	
	
	
	
	/**
	 * 人员的任务详情
	 */
	@RequestMapping(value="/selectUerManagerTaskDetails/{task_id}/{userManager_id}",method=RequestMethod.GET)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<UserManagerTaskModel> selectUerManagerTaskDetails(@PathVariable Long task_id,@PathVariable Long userManager_id) throws ParseException{
		
		ResponseMessage<UserManagerTaskModel> message = new ResponseMessage<UserManagerTaskModel>();
		try {
			UserManagerTaskModel userManagerTaskModel = userManageServiceImpl.selectUerManagerTaskDetails(task_id,userManager_id);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			message.setResult(userManagerTaskModel);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;
	}
	
	/**
	 * 人员任务的编辑
	 */
	@RequestMapping(value="/updateUerManagerTask",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<UserManagerTask> updateUerManagerTask(@RequestBody UserManagerTask userManagerTask) throws ParseException{
		
		ResponseMessage<UserManagerTask> message = new ResponseMessage<UserManagerTask>();
		try {
			userManageServiceImpl.updateUerManagerTask(userManagerTask);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;
	}
	
	/**
	 * 为消费者分配店员下拉选
	 */
	@RequestMapping(value="/selectAllUserManager",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
    public ResponseMessage<List<BaseUserManage>> selectAllUserManager(@RequestBody Map<String,Object> map) throws ParseException{
		
		ResponseMessage<List<BaseUserManage>> message = new ResponseMessage<List<BaseUserManage>>();
		try {
			List<BaseUserManage> baseUserManageList = userManageServiceImpl.selectAllUserManager(map);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			message.setResult(baseUserManageList);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;
	}
	
	/**
	 * 为消费者分配店员
	 */
	@RequestMapping(value="/updateCustomerUserManager",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
    public ResponseMessage updateCustomerUserManager(@RequestBody Map<String,Object> map) throws ParseException{
		ResponseMessage message = new ResponseMessage();
		try {
			userManageServiceImpl.updateCustomerUserManager(map);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;
	}
	
	
	/**
	 * 批量为消费者分配店员
	 */
	@RequestMapping(value="/updateCustomerUserManagerBath",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
    public ResponseMessage updateCustomerUserManagerBath(@RequestBody Map<String,Object> map) throws ParseException{
		ResponseMessage message = new ResponseMessage();
		try {
			userManageServiceImpl.updateCustomerUserManagerBath(map);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;
	}

	/**
	 * 为导购设置任务推广时间开始和活动时间结束的回显    参数：活动id
	 */
	@RequestMapping(value="/selectActivityTime/{activity_id}",method=RequestMethod.GET)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<BaseActivityInfo> selectActivityTime(@PathVariable Integer activity_id) throws ParseException{
		
		ResponseMessage<BaseActivityInfo> message = new ResponseMessage<BaseActivityInfo>();
		try {
			BaseActivityInfo baseActivityInfo = userManageServiceImpl.selectActivityTime(activity_id);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			message.setResult(baseActivityInfo);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}
		return message;
	}
}
